// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Eggman Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// Aliases
private alias 45 : TYPE_EGGMAN


// Static Values

// Tables

event ObjectMain
	switch object.state
	case 0
		object[-1].state = 0
		BoxCollisionTest(C_TOUCH, object.entityPos, -92, -92, 0, 92, 0, 1, 1, 1, 1)
		if checkResult == 1
			object.frame = 1
			object.state = 1
		end if
		break
	case 1
		object[-1].state = 0
		object.animationTimer++
		if object.animationTimer >= 24
			object.state = 2
		end if
		break
	case 2
		if object[0].xpos < object[+1].xpos
			object[+1].state = 1
		end if
		object.xpos += 0x20000
		temp0 = object.xpos
		temp0 -= 0x500000
		if object[0].xpos > temp0
			object.xpos = object[0].xpos
			object.xpos += 0x500000
		end if
		object.animationTimer++
		if object.animationTimer >= 6
			object.animationTimer = 0
			object.frame++
			if object.frame > 4
				object.frame = 2
			end if
		end if
		object.value4++
		switch object.value4
		case 1
			object.value0 = object.xpos
			object.value0 -= 0x70000
			object.value1 = object.ypos
			object.value1 -= 0x180000
			object.value2 = 0
			object.value3 = 1
			break
		case 2
		case 3
		case 4
		case 5
		case 6
		case 7
		case 8
			object.value0 -= 0x10000
			object.value2 += 0x1C00
			object.value1 += object.value2
			break
		case 9
			object.value3 = 0
			break
		case 32
			object.value4 = 0
			break
		end switch
		temp0 = object[+9].xpos
		temp0 -= object.xpos
		if temp0 <= 0x2C0000
			object.xpos = object[+9].xpos
			object.xpos -= 0x2C0000
			object.yvel = -0x20000
			object.frame = 2
			object.value3 = 0
			object.state = 3
		end if
		break
	case 3
		object.xpos += 0xA000
		object.ypos += object.yvel
		object.yvel += 0x1000
		if object.ypos >= object[+9].ypos
			PlaySfx(SfxName[Machine Move], 0)
			object[+9].state = 2
			object.type = TypeName[Blank Object]
		end if
		break
	end switch
end event


event ObjectDraw
	if object.value3 == 1
		DrawSpriteXY(5, object.value0, object.value1)
	end if
	DrawSprite(object.frame)
end event


event ObjectStartup
	LoadSpriteSheet("DEZ/Objects.gif")
	if saveRAM[495] == 0
		SpriteFrame(-16, -26, 32, 52, 1, 58)	//Idle
		SpriteFrame(-16, -26, 32, 52, 34, 58)	//Hurt
		SpriteFrame(-30, -27, 58, 43, 67, 58)	//Run I
		SpriteFrame(-30, -27, 46, 55, 126, 58)	//Run II
		SpriteFrame(-30, -27, 51, 52, 173, 58)	//Run III
		SpriteFrame(-5, -2, 12, 5, 256, 52)
		SpriteFrame(-16, -26, 32, 52, 225, 58)	//Laughing I
		SpriteFrame(-16, -25, 32, 51, 258, 58)	//Laughing II
	else
		SpriteFrame(-17, -30, 32, 56, 1, 256)
		SpriteFrame(-17, -30, 32, 56, 100, 256)
		SpriteFrame(-26, -28, 54, 44, 133, 256)
		SpriteFrame(-18, -27, 37, 53, 188, 256)
		SpriteFrame(-18, -27, 31, 56, 226, 256)
		SpriteFrame(-5, -2, 12, 5, 256, 52)
		SpriteFrame(-17, -30, 32, 56, 34, 256)
		SpriteFrame(-17, -30, 32, 56, 67, 256)
	end if
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
